﻿/****************************************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
	Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BaoJianSoft.Platform;
using BaoJianSoft.Common;
using BaoJianSoft.RapidWeb;

namespace BaoJianSoft.Web
{
	public partial class MyProfile : Page
	{
		private static IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();
		private static IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

		protected void Page_Load(object sender, EventArgs e)
		{
			if (authenticationContext.Identity.IsAuthenticated)
			{
				Guid userId = SpringContext.Current.GetObject<IAuthenticationContext>().User.UserId;
				Guid organizationId = SpringContext.Current.GetObject<IAuthenticationContext>().User.OrganizationId;
				OrganizationObject organization = organizationApi.GetOrganization(organizationId);
				if (organization == null)
					Response.Redirect(WebUtility.PageNotFoundUrl, true);

				OrganizationTypeObject organizationType = organizationApi.GetOrganizationType(organization.OrganizationTypeId);
				if (organizationType == null)
					Response.Redirect(WebUtility.PageNotFoundUrl, true);

				string redirectPageUrl = string.Format("~/UserManagement/DetailPanel.svc?entityid={0}&rendermode=View&stamp={1}&domain={2}", userId, DateTime.Now.Ticks, organizationType.Domain);
				Response.Redirect(redirectPageUrl);
			}
		}
	}
}

